import Vue from 'vue'
import Vuex from 'vuex'
import axios from 'axios'
import VueAxios from 'vue-axios'
// import $ from "jquery"
Vue.prototype.axios = axios
Vue.use(VueAxios, axios)
Vue.use(Vuex)

export default new Vuex.Store({
        state: {
            searchsongid: 0, //搜索歌曲id
            // url: '', //audio
            search: "", //myheader的搜索
            searchlist: [],
            // ---------------------------------------
            // 喜欢音乐列表 myfavorite组件
            //用户id  1759277956
            myfavoriteSongList: [],
            //  首页歌曲id
            myfavoriteSongid: 0,
            // -----------------------------------------------
            //歌词部分  myfavorite和lyric交互
            lyric: [],
            restext: [],

        },
        mutations: {
            //搜索歌曲id
            mgetsearch(state, s) {
                state.search = s;
                // console.log(state.search);
            },
            // ----------------喜欢音乐列表 myfavorite组件-------------------
            myfavoriteGetSongList(state) {
                console.log(state.myfavoriteSongList);
            },
            getmfid(state, id) {
                state.id = id;
            },
            // -- -- -- -- -- -- -- --歌词部分 myfavorite和lyric交互-- -- -- -- -- -- -- -- -- -- -- -- -
            mgetlyric(state, lyric, restext) {
                state.lyric = lyric;
                state.restext = restext;

            },
            mgetHuayu(state) {
                console.log(state);
            },

        },
        actions: {
            //搜索组件的歌曲列表
            agetsearch(context) {
                //  + context.state.search
                context.commit("mgetsearch", context.state.search);
                // console.log("dddddddddddd");
                console.log(context.state.search);
                axios.get("http://localhost:3000/search?keywords=" + context.state.search)
                    .then(function(res) {
                            // console.log('5555555555'); //data.result.songs
                            // console.log(res.data.result.songs); //[0].name
                            context.state.searchlist = res.data.result.songs;
                            console.log(context.state.searchlist);

                        },
                        function(erro) {
                            console.log(erro);
                        });

            },
            amyfavoriteGetSongList(context) {
                context.commit("myfavoriteGetSongList", context.state.myfavoriteSongList);
                axios.get('http://localhost:3000/search?keywords=毛不易')
                    .then(function(res) {
                        // console.log('ggggggggggggggggggggggggggggg');
                        context.state.myfavoriteSongList = res.data.result.songs;
                        // console.log(context.state.myfavoriteSongList);
                    }, function(error) {
                        console.log(error);
                    });
            },
            //华语推荐歌单
            getHuayuPush(context) {
                context.commit("mgetHuayu");
                // var that = this;
                axios.get("http://localhost:3000/top/playlist?limit=10&cat=华语").then(
                    function(res) {
                        console.log("kkkkkkkkkkkkkkkkkkkkkkkkk");
                        console.log(res.data);
                    },
                    function(error) {
                        console.log(error);
                    }
                );

            },

        },
        modules: {}
    })
    // 喜欢音乐列表

// 说明 : 调用此接口 , 传入用户 id, 可获取已喜欢音乐id列表(id数组)

// 必选参数 : uid: 用户 id

// 接口地址 : /likelist

// 调用例子 : /likelist?uid=32953014